﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

using SocialIn.Core;
using SocialIn.Biz;


namespace SocialIn.Web.Members
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //User.Identity.Name;
            if (!IsPostBack)
            {
                if (HttpContext.Current.Session[ConfigName.SessionMember] == null)
                {
                    txtID.Focus();
                }
                else
                {
                    Response.Redirect("/Main.aspx");
                }
            }
        }
        

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            //Response.Write(txtPWD.Text);
            //Response.Write(strHashedPassword);
            SocialIn.Core.Data.Result<bool> result = new Core.Data.Result<bool>();
            Connect connect = new Connect();
            string strHashedPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPWD.Text, "sha1");
            if (connect.LogIn(txtID.Text, strHashedPassword, out result))
            {
                FormsAuthentication.RedirectFromLoginPage(txtID.Text, false);
            }
            else
            {
                Page.RegisterStartupScript("error", "<script type='text/javascript'>alert('아이디와 비밀번호를 확인하세요.');</script>");
            }   
        }

    }
}